﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using SqEngine.Audio;
using sqengine.Engine.Common;
using SqEngine;

namespace sqengine.Components
{
    #region ChatEvent
    public class ChatEvent : System.EventArgs
    {
        private string message = "";
        private string player_name = "";
        private DateTime time;

        public ChatEvent(string msg, string player_name, DateTime time)
        {
            this.message = msg;
            this.player_name = player_name;
            this.time = time;
        }

        public string Message()
        {
            return message;
        }

        public string PlayerName()
        {

            return player_name;
        }

        public DateTime Time()
        {
            return time;
        }

    }
    #endregion

    public class ChatHandler
    {
        private Game _game;
        private Color _msg_color;
        private string _chat_icon;

        // delegate declarationE
        public delegate void _OnMessage(object sender, ChatEvent ce);
        public event _OnMessage OnMessage;

        public ChatHandler(Game game, Color msg_color, string chat_icon)
        {
            _game = game;
            _chat_icon = chat_icon;
            _msg_color = msg_color;
        }

        public void SendMessage(string PlayerName, string message)
        {
            ChatEvent ce = new ChatEvent(message, PlayerName, DateTime.Now);

            ((sqengine)_game).AddMessage(PlayerName + "> " + message, _msg_color, 2000, _chat_icon);


            if (OnMessage != null)
                OnMessage(this, ce);

        }
    }
}
